#ifndef GAMEGUI_H
#define GAMEGUI_H

#include <CEGUI.h>
#include <RendererModules/Ogre/CEGUIOgreRenderer.h>
#include <OgreRoot.h>
#include <OgreSceneManager.h>
#include "VideoSettings.h"
#include "SettingsManager.h"

class GameGUI
{
public:
	GameGUI(Ogre::RenderWindow *window);
	~GameGUI(void);
	void init(VideoSettings *videoSettings);
	void update(Ogre::Real elapsedTime);
	void onGlobalCharacterKey(const CEGUI::uint key);
	//retunrs number of active windows
	int activeWindows();
	void setSaveExists(const bool exists);
	SettingsManager* getTexts();
	bool openStoryWindow(const string text, int speakerID);
	bool changeClass(int classID);
	bool openWeaponSelect(void);
private:
	void restoreSettings(void);
	// Fuctions for main menu buttons
	bool continueGame(const CEGUI::EventArgs &evt);
	bool loadGame(const CEGUI::EventArgs &evt);
	bool newGame(const CEGUI::EventArgs &evt);
	bool openOptions(const CEGUI::EventArgs &evt);
	bool quitGame(const CEGUI::EventArgs &evt);
	// Fuctions for skill menu buttons
	bool increaseHealth(const CEGUI::EventArgs &evt);
	bool increaseEnergy(const CEGUI::EventArgs &evt);
	bool increaseCombat(const CEGUI::EventArgs &evt);
	string evaluateClass(float health, float energy, float combat, int classID);
	bool closeSkillMenu(const CEGUI::EventArgs &evt);
	bool openSkillMenu(const CEGUI::EventArgs &evt);
	// Fuctions for options menu buttons
	bool cancelOptions(const CEGUI::EventArgs &evt);
	bool submitOptions(const CEGUI::EventArgs &evt);
	//Functions for HUD
	bool updateHUD(void);
	//Functions for TextDisplay
	bool storyButton(const CEGUI::EventArgs &evt);
	//Functions for ClassSelection
	bool selectMelee(const CEGUI::EventArgs &evt);
	bool selectRanged(const CEGUI::EventArgs &evt);

    CEGUI::OgreRenderer* mpRenderer;
	Ogre::RenderWindow *mpWindow;
	VideoSettings *mpVideoSettings;
	// Window for system output
	CEGUI::MultiLineEditbox *mpSysOutputWnd;
	// Text output at the middle of the screen
	CEGUI::Window *mpTextOutput;
	// Main menu
	CEGUI::Window *mpMainMenu;
	CEGUI::PushButton *mpContinueButton;
	CEGUI::PushButton *mpLoadGameButton;
	CEGUI::PushButton *mpNewGameButton;
	CEGUI::PushButton *mpOptionsButton;
	CEGUI::PushButton *mpQuitButton;
	// Skill menu
	CEGUI::Window *mpSkillMenu;
	CEGUI::Window *mpSP;
	CEGUI::Window *mpClass;
	// Skill bars
	CEGUI::ProgressBar *mpHealthBar;
	CEGUI::ProgressBar *mpEnergyBar;
	CEGUI::ProgressBar *mpCombatBar;
	// Options menu
	CEGUI::Window *mpOptionsMenu;
	//HUD
	CEGUI::Window *mpHUD;
	CEGUI::ProgressBar *mpHUDHealth;
	CEGUI::ProgressBar *mpHUDEnergy;
	CEGUI::ProgressBar *mpHUDEXP;
	CEGUI::PushButton *mpHUDButton;
	//TextDisplay
	CEGUI::Window *mpStoryWindow;
	CEGUI::Window *mpStoryDisplay;
	CEGUI::Window *mpStoryImage;
	CEGUI::PushButton *mpStoryButton;
	//ClassSelection
	CEGUI::Window *mpClassSelection;
	CEGUI::PushButton *mpMeleeSelection;
	CEGUI::PushButton *mpRangedSelection;
	// Shows if State_Initializing was the last state of the game
	bool mbInit;
	bool mSaveExists;
	SettingsManager* mTexts;
};

extern GameGUI *gpGUI;

// Declaration for streams to show output in the game
using std::endl;
extern std::stringstream sysout;
extern std::stringstream frontout;

#endif